package org.jeecg.chase.common.engine.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.chase.common.base.data.BaseQuery;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author leikai
 * @version 1.0
 * @description:
 * @date 2021/07/23/0023 17:27
 */
@Transactional
public abstract class AbstractDataEngine extends AbstractDataEngineSurport {


    /**
     * 列表查询
     *
     * @param baseQuery
     * @return java.util.List<?>
     * @author leikai
     * @date 2021/07/26/0026 17:51
     */
    public List<?> getList(BaseQuery baseQuery) {

        return (List<?>) executeQuery(

                baseQuery,
                (query, resultClass) -> {
                    return doGetList(query, resultClass);
                },
                (queryResult) -> {
                    return (List) queryResult;
                }
        );
    }

    /**
     * 分页查询
     *
     * @param baseQuery
     * @return org.jeecg.chase.common.dataaccess.data.Page<?>
     * @author leikai
     * @date 2021/07/26/0026 17:51
     */
    public Page<?> getPage(BaseQuery baseQuery) {

        return (Page<?>) executeQuery(

                baseQuery,
                (query, resultClass) -> {
                    return doGetPage(query, resultClass);
                },
                (queryResult) -> {
                    Page page = (Page) queryResult;
                    return page.getRecords();
                }
        );
    }

    /**
     * 列表查询
     *
     * @param query
     * @param resultClass
     * @return java.util.List<?>
     * @author leikai
     * @date 2021/07/26/0026 17:52
     */
    public abstract List<?> doGetList(BaseQuery query, Class<?> resultClass);


    /**
     * 分页列表查询
     *
     * @param query
     * @param resultClass
     * @return org.jeecg.chase.common.dataaccess.data.Page<?>
     * @author leikai
     * @date 2021/07/26/0026 17:52
     */
    public abstract Page<?> doGetPage(BaseQuery query, Class<?> resultClass);
}
